#include <QPainter>

#include <UIKit/UIFont.h>

#include "AppIconView.h"

AppIconView::AppIconView (const QImage& icon,
                          const QString& title, 
                          QGraphicsItem *parent) 
    : UIControl(parent)
{
    m_icon = icon;
    m_title = title;
}

AppIconView::~AppIconView() {
}

void AppIconView::drawRect (QPainter *painter, const QRect& rect) {
    painter->save();

    painter->setFont(UIFontTinyBold(painter->font()));
    painter->drawImage(rect.x() + (rect.width() / 2 - m_icon.width() / 2), 0, 
                       m_icon);

    painter->setPen(Qt::white);
    int textFlags = (Qt::AlignTop | Qt::AlignHCenter | Qt::TextWrapAnywhere);
    painter->drawText(rect.x(), rect.y() + m_icon.height(), 
                      rect.width(), rect.height() - m_icon.height(), 
                      textFlags, m_title);

    painter->restore();
}

